home *** CD-ROM | disk | FTP | other *** search
- /****************************************************************************/
- /* DATABOSS MODULE: DB_MAN.C */
- /****************************************************************************/
-
- #include "db_lsc.h"
-
- #ifndef __TURBOC__
- #include <graph.h>
- #include <sys\types.h>
- #define _close(h) close(h)
- #endif
- #include <io.h>
- #include <fcntl.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <sys\stat.h>
-
- #include "db_types.h"
- #include "db_curs.h"
- #include "db_file.h"
- #include "db_funcs.h"
- #include "db_gvar.h"
- #include "db_heap.h"
- #include "db_key.h"
- #include "db_math.h"
- #include "db_str.h"
- #include "db_win.h"
- #include "db_mnu.h"
- #include "db_util.h"
- #include "db_man.h"
- #include "db_uwin.h"
-
- /**************************** GLOBAL VARIABLES ****************************/
-
- bool manrecur;
-
- /*************************** INTERNAL CONSTANTS ***************************/
-
- #define PaperLen 66
- #define GoodLines 60
- #define MaxLines 100
- #define MaxIOP 100
-
- /***************************** INTERNAL TYPES *****************************/
-
- typedef struct ixfind {
- uchar ich;
- int ipg;
- int ixp;
- int iyp;
- int split;
- str4 pgstr;
- } ixfind;
- typedef struct ovfind {
- int opg;
- int oyp;
- str4 pgstr;
- } ovfind;
- typedef struct manrec {
- string name;
- long endfile;
- } manrec;
-
- /*************************** INTERNAL VARIABLES ***************************/
-
- static uchar blank[] = "\xFF\x01\x50 ";
-
- static byte whb = 0x1F;
- static byte yhb = 0x1E;
- static byte rhb = 0x1C;
- static byte whc = 0x3F;
-
- static pathstr outdev;
- static int out;
- static byte wrattr;
- static long lines[MaxLines+1];
- static winptr mw,cwinp;
- static word pageno;
- static int manfile;
- static manhdr manh;
- static manrec manual;
- static prefaptr mpages;
- static crefaptr mchaps;
- static pref ipages[MaxIOP+1];
- static pref opages[MaxIOP+1];
- static ixfind ixf;
- static ovfind ovf;
- static string crossref;
- static mnufrec rm;
-
- static bool initialized = False;
-
- /***************************** IMPLEMENTATION *****************************/
-
- void writeout(string wstr, byte wa, byte wx, byte wy)
- {
- int p;
- string ts,twstr;
-
- strcpy(twstr,wstr);
- if (outdev[0] == '\0')
- writewxy(twstr,wa,wx,wy,mw);
- else {
- p = strposstr("\xFF\x02",twstr);
- while (p >= 0) {
- strdelete(twstr,p,3);
- p = strposstr("\xFF\x02",twstr);
- }
- p = strposstr("\xFF\x01",twstr);
- while ((p >= 0) && (p < (strlen(twstr)-3))) {
- fillstr(ts,twstr[p+2],twstr[p+3]);
- strdelete(twstr,p,4);
- strinsert(ts,twstr,p);
- p = strposstr("\xFF\x01",twstr);
- }
- for (p = 0; p < strlen(twstr); p++)
- twstr[p] = filterch(twstr[p],IBMGraphics);
- chkwrite(out,twstr,True);
- if (pabort > 0) outdev[0] = '\0';
- }
- }
-
- void setcpos(word yp, word xofs, string ts)
- {
- int i;
-
- ixf.iyp = yp;
- ixf.ixp = strposch(',',ts);
- if (ixf.ixp >= 0) {
- ixf.ixp++;
- strcopy(ixf.pgstr,ts,ixf.ixp,4);
- i = strposch(',',ixf.pgstr);
- if (i >= 0) strcopy(ixf.pgstr,ixf.pgstr,0,i);
- strip(ixf.pgstr,ixf.pgstr);
- ixf.ixp += xofs;
- }
- ixf.ixp++;
- }
-
- void ixpage(word maxl, word ipno, bool active, winptr mw)
- {
- word half,b,i,j;
- byte len;
- string ts,tts;
-
- mw->disp = False;
- i = 1;
- j = 0;
- if (ipno == 1) ixf.ich = ' ';
- half = mw->mwid/2;
- lseek(manfile,ipages[ipno],SEEK_SET);
- do {
- if ((tell(manfile) < manual.endfile) && (i <= maxl-2)) {
- if ((outdev[0] != '\0') && (i > GoodLines)) {
- writeout("\x0C",0,1,(byte) i);
- i = 1;
- j = 0;
- }
- read(manfile,&len,1);
- if (len > 0) read(manfile,ts,len);
- ts[len] = '\0';
- }
- else
- strcpy(ts," ");
- if ((ts[0] != ixf.ich) && (ts[0] != ' ')) {
- if (((byte) ts[0]) > ((byte) ixf.ich)) {
- if (active) {
- strcpy(tts,"« »");
- tts[1] = ts[0];
- writeout(pad(tts,tts,half,Right),(byte)(revattr(whc)|0x08),(byte)(j*half+1),(byte)(i));
- }
- i++;
- if (i > maxl) {
- i = 1;
- j++;
- }
- }
- ixf.ich = ts[0];
- }
- if (strlen(ts) >= half) {
- if (active) {
- b = half-1;
- while ((b > (half - 7)) && (ts[b-1] != ',')) b--;
- writeout(pad(tts,strcopy(tts,ts,0,b-1),half,Right),whc,(byte)(j*half+1),(byte)(i));
- if (ixf.ixp == 0) {
- setcpos(i,0,strcopy(tts,ts,0,b-1));
- if (ixf.ixp != 0) ixf.split = 1;
- }
- strdelete(ts,0,b-1);
- strinsert(" ",ts,0);
- }
- i++;
- if (i > maxl) {
- i = 1;
- j++;
- }
- }
- if (active && ((outdev[0] == '\0') || (strcmp(ts," ") != 0))) {
- pad(ts,ts,half,Right);
- writeout(ts,whc,(byte)(j*half+1),(byte)(i));
- if (ixf.ixp == 0) setcpos(i,0,ts);
- }
- i++;
- if (i > maxl) {
- i = 1;
- j++;
- }
- } while (j <= 1);
- if (outdev[0] != '\0') writeout("\x0C",0,1,(byte) i);
- mw->disp = True;
- }
-
- void ovpage(word maxl, word opno, bool active, winptr mw)
- {
- int i,lastnum;
- string s1,s2,tl,ts;
- byte len;
-
- mw->disp = False;
- i = 1;
- lastnum = 0;
- lseek(manfile,opages[opno],SEEK_SET);
- do {
- if ((tell(manfile) < manh.sindex) && (i <= (maxl-1))) {
- if ((outdev[0] != '\0') && (i > GoodLines)) {
- writeout("\x0C",0,1,(byte) i);
- i = 1;
- }
- read(manfile,&len,1);
- if (len > 0) read(manfile,s1,len);
- s1[len] = '\0';
- read(manfile,&len,1);
- if (len > 0) read(manfile,s2,len);
- s2[len] = '\0';
- strcpy(tl,s2);
- strcpy(ts,"\xFF\x01 .");
- ts[2] = mw->mwid-6-strlen(tl);
- strcat(tl,ts);
- read(manfile,&len,1);
- if (len > 0) read(manfile,s2,len);
- s2[len] = '\0';
- strcat(tl,pad(ts,s2,5,Left));
- strcat(tl," ");
- if (((int) fint(valu(s1))) > lastnum) {
- if (i > 1) {
- if (active) writeout(blank,whc,1,(byte) i);
- i++;
- }
- lastnum = (int) fround(fint(valu(s1)));
- }
- if (active) writeout(tl,whc,1,(byte) i);
- }
- else {
- strcpy(s1," ");
- strcpy(s2," ");
- strcpy(tl,blank);
- if (active && (outdev[0] == '\0')) writeout(tl,whc,1,(byte) i);
- }
- i++;
- } while (i <= maxl);
- if (outdev[0] != '\0') writeout("\x0C",0,1,(byte) i);
- mw->disp = True;
- }
-
- void initmanual(pathstr manname)
- {
- word w;
- wintyp tw;
- string ts;
- byte len;
-
- if (manstate == _opened) {
- outdev[0] = '\0';
- pageno = 1;
- manrecur = False;
- db_free(mpages);
- db_free(mchaps);
- _close(manfile);
- }
- if (manstate == _located) {
- wrattr = swc;
- message(NULL,centre(ts,LSC_LoadingManual,76));
- manual.endfile = filelength(manfile);
- read(manfile,(void *)&manh,sizeof(manhdr));
- mpages = db_malloc((manh.totpages+2)*sizeof(pref));
- mchaps = db_malloc((manh.totchaps+2)*sizeof(cref));
- lseek(manfile,manh.sinfo,SEEK_SET);
- for (w = 1; w <= manh.totpages; w++)
- read(manfile,(void *)&(*mpages)[w],sizeof(pref));
- for (w = 1; w <= manh.totchaps; w++)
- read(manfile,(void *)&(*mchaps)[w],sizeof(cref));
- read(manfile,&len,1);
- if (len > 0) {
- read(manfile,manual.name,len);
- manual.name[len] = 0;
- }
- manh.totpages--;
- manh.totchaps--;
- tw.mhgt = scrhgt - 5;
- tw.mwid = scrwid - 2;
- ixf.ipg = 1;
- ipages[1] = manh.sindex;
- lseek(manfile,manh.sindex,SEEK_SET);
- do {
- ixpage(tw.mhgt,ixf.ipg,False,&tw);
- ixf.ipg++;
- ipages[ixf.ipg] = tell(manfile);
- } while (tell(manfile) < manual.endfile);
- for (w = ixf.ipg; w <= MaxIOP; w++) ipages[w] = 0;
- ovf.opg = 1;
- opages[1] = manh.soview;
- lseek(manfile,manh.soview,SEEK_SET);
- do {
- ovpage(tw.mhgt,ovf.opg,False,&tw);
- ovf.opg++;
- opages[ovf.opg] = tell(manfile);
- } while (tell(manfile) < manh.sindex);
- for (w = ovf.opg; w <= MaxIOP; w++) opages[w] = 0;
- manstate = _opened;
- message(NULL,"");
- }
- else {
- manstate = _closed;
- fsearch(ts,manname,lookalong);
- if (ts[0] == '\0') strcpy(ts,manname);
- manfile = open(ts,O_BINARY | O_RDWR, S_IREAD | S_IWRITE);
- if (manfile == -1) manstate = _lost; else manstate = _located;
- }
- }
-
- void nextcpos(byte dirn)
- {
- int tpos,half,i,j,ty1,ty2,l1;
- string tl,ts,ta;
-
- half = mw->mwid/2;
- i = ixf.iyp;
- j = (ixf.ixp < half) ? 0 : 1;
- if ((dirn == _Left_) || (dirn == _Right_)) {
- if (ixf.split > 0) {
- if (ixf.split == 1) {
- ty1 = ixf.iyp;
- ty2 = ty1 + 1;
- }
- else {
- ty2 = ixf.iyp;
- ty1 = ty2-1;
- }
- getline((byte)(j*half+1),(byte)(ty1),(byte)(half),tl,ta,mw);
- trim(tl,tl);
- l1 = strlen(tl);
- getline((byte) (j*half+1),(byte)(ty2),(byte)(half),ts,ta,mw);
- strcat(tl,mirt(ts,ts));
- }
- else
- getline((byte)(j*half+1),(byte)(ixf.iyp),(byte)(half),tl,ta,mw);
- }
- switch (dirn) {
- case _Up_ :
- do {
- i--;
- if (i <= 0) {
- i = mw->mhgt;
- j--;
- }
- if (j >= 0)
- getline((byte)(j*half+1),(byte)(i),(byte)(half),tl,ta,mw);
- else
- tl[0] = '\0';
- } while ((j >= 0) && ((strcmp(strcopy(ts,tl,0,2)," ") == 0) ||
- (strposch(',',tl) == -1)));
- if (j >= 0) {
- setcpos(i,(j*half),tl);
- ixf.split = 0;
- if (i < mw->mhgt) {
- getline((byte)(j*half+1),(byte)(i+1),(byte)(half),tl,ta,mw);
- if ((strcmp(strcopy(ts,tl,0,2)," ") == 0) && (strposch(',',tl) >= 0))
- ixf.split = 1;
- }
- }
- break;
- case _Down_ :
- do {
- i++;
- if (i > mw->mhgt) {
- i = 1;
- j++;
- }
- if (j < 2)
- getline((byte)(j*half+1),(byte)(i),(byte)(half),tl,ta,mw);
- else
- tl[0] = '\0';
- } while ((j <= 1) && ((strcmp(strcopy(ts,tl,0,2)," ") == 0) || (strposch(',',tl) < 0)));
- if (j <= 1) {
- setcpos(i,(j*half),tl);
- ixf.split = 0;
- if (i < mw->mhgt) {
- getline((byte)(j*half+1),(byte)(i+1),(byte)(half),tl,ta,mw);
- if ((strcmp(strcopy(ts,tl,0,2)," ") == 0) && (strposch(',',tl) >= 0))
- ixf.split = 1;
- }
- }
- break;
- case _Left_ :
- ts[0] = ',';
- strcpy(&ts[1],ixf.pgstr);
- tpos = strposstr(ts,tl);
- if (tpos >= 0) {
- do {
- tpos--;
- } while ((tpos >= 0) && (tl[tpos] != ','));
- }
- if (tpos >= 0) {
- setcpos(ixf.iyp,(j*half),strcopy(ts,tl,tpos,12));
- ixf.ixp = ixf.ixp + tpos;
- if (ixf.split > 0) {
- if (ixf.ixp > l1)
- ixf.ixp = ixf.ixp + 2 - l1;
- else {
- if (ixf.split == 2) {
- ixf.iyp--;
- ixf.split--;
- }
- }
- }
- }
- break;
- case _Right_ :
- strcpy(ts,ixf.pgstr);
- strcat(ts,",");
- tpos = strposstr(ts,tl);
- if (tpos >= 0) {
- setcpos(ixf.iyp,(j*half),strcopy(ts,tl,tpos,12));
- ixf.ixp = ixf.ixp + tpos;
- if ((ixf.split > 0) && (ixf.ixp > l1)) {
- if (ixf.split == 1) {
- ixf.iyp++;
- ixf.split++;
- }
- ixf.ixp = ixf.ixp + 2 - l1;
- }
- }
- break;
- }
- }
-
- word findix(string str)
- {
- word w;
-
- w = 0;
- do {
- w++;
- if (ipages[w] != 0) ixpage(mw->mhgt,w,False,mw);
- } while ((((byte) ixf.ich) < ((byte) str[0])) && (ipages[w] != 0));
- return ((ipages[w] != 0) ? w : w-1);
- }
-
- void placeix(string str, bool active)
- {
- word i,j,half,oldp;
- string ts,ta;
-
- i = (strlen(str) < 2) ? findix(str) : ixf.ipg;
- do {
- oldp = ixf.ipg;
- ixf.ipg = i;
- if (ixf.ipg != oldp) {
- ixf.ixp = 0;
- ixpage(mw->mhgt,ixf.ipg,active,mw);
- }
- i = 0;
- j = 0;
- half = mw->mwid/2;
- do {
- i++;
- if (i > mw->mhgt) {
- i = 1;
- j++;
- }
- getline((byte)(j*half+1),(byte)(i),(byte)(half),ts,ta,mw);
- } while (((strcmp(ts,str) < 0) || (ts[0] == 0xAE)) && (j <= 1));
- if (j < 2) {
- ixf.iyp = i;
- ixf.ixp = (j == 0) ? 1 : half+1;
- if (strposch(',',ts) < 0)
- nextcpos(_Down_);
- else
- setcpos(i,(j*half),ts);
- i = ixf.ipg;
- }
- else
- i = ixf.ipg + 1;
- } while ((j >= 2) && (ipages[i] != 0));
- if (active && (oldp != ixf.ipg)) dispwindow(mw);
- }
-
- word pickfromindex(str40 fs, word pno)
- {
- word half,w;
- byte ukey;
- bool refill;
- ixfind savixf;
- string ts,tfs;
-
- strcpy(tfs,fs);
- refill = True;
- half = mw->mwid/2;
- savixf = ixf;
- writewxy(blank,0,1,1,cwinp);
- do {
- if (refill) {
- ixpage(mw->mhgt,ixf.ipg,True,mw);
- dispwindow(mw);
- refill = False;
- }
- if (tfs[0] != '\0') placeix(tfs,True);
- writewxy(ixf.pgstr,0xF0,(byte) ixf.ixp,(byte) ixf.iyp,mw);
- ukey = upperch(getkey());
- writewxy(ixf.pgstr,whc,(byte) ixf.ixp,(byte) ixf.iyp,mw);
- if ((ukey == BackSp) || ((ukey >= '0') && (ukey <= '9')) ||
- ((ukey >= 'A') && (ukey <= 'Z'))) {
- if (ukey != BackSp)
- strcat(tfs,chstr(ts,ukey));
- else {
- if (tfs[0] != '\0') tfs[strlen(tfs)-1] = '\0';
- }
- strconcat(ts,LSC_SearchFor,"\"",tfs,"\" ",NULL);
- writewxy(ts,yhb,1,1,cwinp);
- }
- else {
- tfs[0] = '\0';
- writewxy(blank,0,1,1,cwinp);
- }
- switch (ukey) {
- case Tab :
- if (ixf.ixp > half) {
- ixf.ixp = 1;
- nextcpos(_Down_);
- }
- else {
- if (ixf.ixp > 0) {
- ixf.ixp = half+1;
- nextcpos(_Up_);
- }
- } break;
- case UArr : nextcpos(_Up_); break;
- case DArr : nextcpos(_Down_); break;
- case LArr : nextcpos(_Left_); break;
- case RArr : nextcpos(_Right_); break;
- case PgUp :
- if (ixf.ipg > 1) {
- ixf.ipg--;
- ixf.ixp = 0;
- refill = True;
- }
- break;
- case PgDn :
- if ((ixf.ipg < MaxIOP) && (ipages[ixf.ipg+1] != 0)) {
- ixf.ipg++;
- ixf.ixp = 0;
- refill = True;
- }
- break;
- }
- } while ((ukey != Enter) && (ukey != QitKey));
- if (ukey == Enter)
- w = (word) ival(ixf.pgstr);
- else {
- w = pno;
- ixf = savixf;
- }
- return (w);
- }
-
- word pickfromoview(word pno)
- {
- int i;
- uchar ukey;
- bool refill;
- ovfind savovf;
- uchar ta[5];
- word fval;
-
- refill = True;
- savovf = ovf;
- do {
- if (refill) {
- ovpage(mw->mhgt,ovf.opg,True,mw);
- getline((byte)(mw->mwid-4),(byte)(ovf.oyp),4,ovf.pgstr,ta,mw);
- dispwindow(mw);
- refill = False;
- }
- writewxy(ovf.pgstr,0xF0,(byte)(mw->mwid-4),(byte)(ovf.oyp),mw);
- ukey = upperch(getkey());
- writewxy(ovf.pgstr,whc,(byte)(mw->mwid-4),(byte)(ovf.oyp),mw);
- switch (ukey) {
- case UArr :
- if (ovf.oyp > 1) {
- do {
- ovf.oyp--;
- getline((byte)(mw->mwid-4),(byte)(ovf.oyp),4,ovf.pgstr,ta,mw);
- } while ((ovf.oyp != 1) && (ival(ovf.pgstr) <= 0));
- }
- break;
- case DArr :
- if (ovf.oyp < mw->mhgt) {
- i = ovf.oyp;
- do {
- i++;
- getline((byte)(mw->mwid-4),(byte)(i),4,ovf.pgstr,ta,mw);
- } while ((i < mw->mhgt) && (ival(ovf.pgstr) <= 0));
- if (ival(ovf.pgstr) > 0)
- ovf.oyp = i;
- else
- getline((byte)(mw->mwid-4),(byte)(ovf.oyp),4,ovf.pgstr,ta,mw);
- }
- break;
- case PgUp :
- if (ovf.opg > 1) {
- ovf.opg--;
- refill = True;
- ovf.oyp = 1;
- }
- break;
- case PgDn :
- if ((ovf.opg < MaxIOP) && (opages[ovf.opg+1] != 0)) {
- ovf.opg++;
- refill = True;
- ovf.oyp = 1;
- }
- break;
- }
- } while ((ukey != Enter) && (ukey != QitKey));
- if (ukey == Enter)
- fval = (word) ival(ovf.pgstr);
- else {
- fval = pno;
- ovf = savovf;
- }
- return (fval);
- }
-
- void additm(mnufrec *m, string pr)
- {
- string ts;
- int tslen;
- mnuptr cm;
- itmptr ci;
-
- m->curitm = (itmptr) db_malloc(sizeof(itmtyp));
- m->curitm->selcmd = (strptr) db_malloc(1); m->curitm->selcmd[0] = '\0';
- m->curitm->selpath = (strptr) db_malloc(1); m->curitm->selpath[0] = '\0';
- m->curitm->selact = (strptr) db_malloc(1); m->curitm->selact[0] = '\0';
- strcpy(ts,pr);
- tslen = strlen(ts);
- m->curitm->prompt = (strptr) db_malloc(tslen+1);
- cm = m->curmnu;
- ci = m->curitm;
- if ((tslen+2) > cm->widm) cm->widm = (byte) (tslen + 2);
- cm->hgtm++;
- strcpy(ci->prompt,ts);
- ci->ix = 2;
- ci->iy = cm->hgtm;
- ci->prpos = 1;
- ci->sec = 0;
- ci->editsec = 0;
- ci->helpwin = NULL;
- ci->selwait = _NO;
- ci->seltyp = ' ';
- strcpy(ci->altern.altcomb," ");
- ci->altern.nxtalt = NULL;
- ci->altern.parmnu = NULL;
- if (cm->fitm == NULL) {
- cm->fitm = ci;
- ci->nitm = ci;
- ci->pitm = ci;
- }
- else {
- ci->pitm = cm->fitm->pitm;
- ci->nitm = cm->fitm;
- cm->fitm->pitm->nitm = ci;
- cm->fitm->pitm = ci;
- }
- }
-
- void makemnu(mnufrec *m)
- {
- mnuptr mnu;
-
- mnu = (mnuptr) db_malloc(sizeof(mnutyp));
- m->mat[0] = mnu;
- mnu->hitm = NULL;
- mnu->winp = NULL;
- mnu->litm = NULL;
- mnu->fitm = NULL;
- mnu->mtyp = Vert;
- mnu->mno = 1;
- mnu->pmnu = 0;
- mnu->xm = 2;
- mnu->ym = 2;
- mnu->widm = 2;
- mnu->hgtm = 0;
- mnu->mnucolr = 15;
- mnu->mbcolr = 9;
- mnu->mshad = 8;
- memcpy(mnu->mbchrs,"─┐│┘─└│┌",8);
- mnu->mtitlej = TopCnt;
- mnu->mtitle[0] = '\0';
- mnu->apc = 3;
- mnu->ipc = 7;
- mnu->hc = 14;
- mnu->sl = 0;
- mnu->hbc = 112;
- m->curmnu = mnu;
- }
-
- void killmnu(mnufrec *m)
- {
- itmptr titm;
-
- zapmnu(m,m->mat[0]);
- titm = m->curmnu->fitm->pitm;
- while (titm != m->curmnu->fitm) {
- titm = titm->pitm;
- db_free(titm->nitm);
- }
- db_free(m->curmnu->fitm);
- db_free(m->curmnu);
- }
-
- strptr xref(str40 sout, string ts)
- {
- int b;
- uchar ukey;
- str40 wkstr;
- string tts;
- uchar ukeystr[2];
-
- trim(tts,mirt(tts,ts));
- if (tts[0] != '\0') {
- for (b = 0; b < MaxMnus; b++) rm.mat[b] = NULL;
- makemnu(&rm);
- rm.curmnu = rm.mat[0];
- rm.curitm = NULL;
- rm.mnufnam[0] = '\0';
- rm.basewin1 = NULL;
- rm.basewin2 = NULL;
- rm.level = 0;
- rm.dx = 0;
- rm.dy = 0;
- rm.altcomb1 = NULL;
- ukey = 'A';
- while ((tts[0] != '\0') && (ukey <= 'W')) {
- b = strposch('|',tts);
- if (b >= 0) {
- trim(wkstr,mirt(wkstr,strcopy(wkstr,tts,0,b)));
- strdelete(tts,0,b+1);
- }
- else {
- trim(wkstr,mirt(wkstr,tts));
- tts[0] = '\0';
- }
- if (wkstr[0] != '\0') {
- strconcat(wkstr,chstr(ukeystr,ukey)," - ",wkstr,NULL);
- ukey++;
- additm(&rm,wkstr);
- }
- }
- rm.curitm = rm.curmnu->fitm;
- rm.mat[0]->xm = (scrwid-rm.mat[0]->widm)/2;
- rm.mat[0]->ym = (scrhgt-rm.mat[0]->hgtm)/2;
- dspmnu(&rm,rm.mat[0]);
- do {
- hbar(&rm);
- ukey = upperch(getkey());
- switch (ukey) {
- case UArr : goud(&rm,Up); break;
- case DArr : goud(&rm,Down); break;
- case Enter : strcpy(sout,rm.curitm->prompt); break;
- case QitKey : sout[0] = '\0'; break;
- default :
- if ((ukey >= 'A') && (ukey <= 'Z'))
- selitm(ukey,&rm);
- break;
- }
- } while ((ukey != Enter) && (ukey != QitKey));
- killmnu(&rm);
- }
- else {
- sout[0] = '\0';
- dberrm(LSC_NoXRefHere);
- }
- return (sout);
- }
-
- void dspln(int lno, int p, int maxl)
- {
- byte b;
- string ts;
- uchar as[5];
-
- read(manfile,&b,1);
- if (b > 0) read(manfile,ts,b);
- ts[b] = '\0';
- if (tell(manfile) >= (*mpages)[p+1]) {
- strcpy(crossref,ts);
- lines[lno] = 0;
- if (lno <= maxl) writeout(blank,wrattr,1,(byte) lno);
- }
- else {
- if (lno <= maxl) {
- b = eslen(ts);
- if (b < mw->mwid) {
- strcpy(as,"\xFF\x01 ");
- as[2] = mw->mwid-b;
- strcat(ts,as);
- }
- writeout(ts,wrattr,1,(byte) lno);
- if (strposstr("\xFF\x02",ts) >= 0) {
- b = (byte) (strlen(ts)-4);
- while ((ts[b] != 0xFF) || (ts[b+1] != 0x02)) b--;
- wrattr = ts[b+2];
- }
- }
- }
- }
-
- void loadpage(word pno, int maxl)
- {
- int lno;
-
- crossref[0] = '\0';
- mw->disp = False;
- lno = 1;
- lseek(manfile,(*mpages)[pno],SEEK_SET);
- do {
- if (tell(manfile) >= (*mpages)[pno+1]) {
- lines[lno] = 0;
- if ((lno <= maxl) && (outdev[0] == '\0')) writeout(blank,wrattr,1,(byte) lno);
- }
- else {
- lines[lno] = tell(manfile);
- dspln(lno,pno,maxl);
- }
- lno++;
- } while (lno <= MaxLines);
- mw->disp = True;
- }
-
- int getchap(word pno)
- {
- int fval;
-
- fval = 0;
- do fval++; while (((*mchaps)[fval] <= pno) && (fval <= manh.totchaps));
- return (fval-1);
- }
-
- void updatepage(word pno, bool lup, bool ldn)
- {
- string ts,tts;
-
- strconcat(ts,LSC_Chapter,istr(ts,(long) getchap(pno),4),", [",
- strip(tts,istr(tts,(long) manh.totchaps,4)),"]",NULL);
- writewxy(ts,yhb,2,1,cwinp);
- strconcat(ts,LSC_Page,istr(ts,(long) pno,4),", [",
- strip(tts,istr(tts,(long) manh.totpages,4)),"]",NULL);
- writewxy(ts,yhb,(byte)(scrwid-strlen(ts)-2),1,cwinp);
- if (lup || ldn) {
- strcpy(ts,LSC_EndOfPage);
- if (lup) ts[0] = '\x18';
- if (ldn) ts[strlen(ts)-1] = '\x19';
- }
- else
- pad(ts,"",strlen(LSC_EndOfPage),Right);
- writewxy(ts,yhb,(byte)((cwinp->mwid-strlen(ts))/2),1,cwinp);
- }
-
- bool chkpage(string instr)
- {
- return ((bool) ((ival(instr) >= 1) && (ival(instr) <= manh.totpages)));
- }
-
- bool chkchap(string instr)
- {
- return ((bool) ((ival(instr) >= 1) && (ival(instr) <= manh.totchaps)));
- }
-
- bool chkdev(string instr)
- {
- string ts,tts;
-
- return ((bool) ((strcmp(strip(ts,instr),trim(tts,instr)) == 0) &&
- (strcmp(strip(ts,instr),"CON") != 0)));
- }
-
- void printman(word pno)
- {
- string ts,ts1,ts2,ts3,ts4;
- uchar form[4];
- word w,last,first;
- int savds;
-
- first = pageno;
- last = pageno;
- strconcat(ts,LSC_PrintOverview,"|",LSC_PrintIndex,"|",LSC_PrintByPages,"|",LSC_PrintByChapters,NULL);
- xref(ts,ts);
- if (ts[0] != '\0') {
- exitcode = ' ';
- form[0] = '4';
- form[1] = Pic_H;
- form[2] = '\0';
- switch (ts[0]) {
- case 'C' :
- dbgetstr(ts1,_Num,strconcat(ts2,LSC_EnterBeginning," ",LSC_Page,NULL),
- fstr(ts3,(double) first,4,0),form,
- strconcat(ts4,LSC_Page," ",LSC_OutOfRange,NULL),chkpage,nohelp);
- first = (word) ival(ts1);
- if (exitcode != QitKey) {
- dbgetstr(ts1,_Num,strconcat(ts2,LSC_EnterEnding," ",LSC_Page,NULL),
- fstr(ts3,(double) first,4,0),form,
- strconcat(ts4,LSC_Page," ",LSC_OutOfRange,NULL),chkpage,nohelp);
- last = (word) ival(ts1);
- }
- if (first > last) exitcode = QitKey;
- break;
- case 'D' :
- dbgetstr(ts1,_Num,strconcat(ts2,LSC_EnterBeginning," ",LSC_Chapter,NULL),
- fstr(ts3,(double) first,4,0),form,
- strconcat(ts4,LSC_Chapter," ",LSC_OutOfRange,NULL),chkchap,nohelp);
- first = (word) ival(ts1);
- if (exitcode != QitKey) {
- dbgetstr(ts1,_Num,strconcat(ts2,LSC_EnterEnding," ",LSC_Chapter,NULL),
- fstr(ts3,(double) first,4,0),form,
- strconcat(ts4,LSC_Chapter," ",LSC_OutOfRange,NULL),chkchap,nohelp);
- last = (word) ival(ts1);
- }
- if (first <= last) {
- first = (*mchaps)[first];
- last = (*mchaps)[last+1]-1;
- if (last < first) last = first;
- }
- else exitcode = QitKey;
- break;
- }
- if (exitcode != QitKey) {
- strcpy(form,"12");
- form[2] = Pic_U;
- form[3] = '\0';
- dbgetstr(ts1,_Ch,LSC_EnterOutDevice,"PRN",form,LSC_CONInvalid,chkdev,nohelp);
- strcpy(outdev,strip(ts1,ts1));
- }
- if (exitcode != QitKey) {
- savds = deltas;
- deltas = 0;
- out = open(outdev,O_TEXT | O_RDWR, S_IREAD | S_IWRITE);
- if (out != -1) {
- message(cwinp,LSC_WaitWhilePrinting);
- switch (ts[0]) {
- case 'A' : ovpage(PaperLen,1,True,mw); break;
- case 'B' : ixpage(PaperLen,1,True,mw); break;
- case 'C' :
- case 'D' :
- for (w = first; w <= last; w++) {
- strconcat(ts1,LSC_Page," : ",istr(ts1,(long) w,4),NULL);
- writeout(pad(ts1,ts1,77,Left),1,1,1);
- loadpage(w,GoodLines);
- if (outdev[0] != '\0') writeout("\x0C",1,1,1);
- }
- break;
- }
- _close(out);
- message(cwinp,"");
- deltas = savds;
- }
- else
- dberrm(LSC_DeviceNotReady);
- }
- }
- outdev[0] = '\0';
- }
-
- void dispmanual(void)
- {
- uchar ukey;
- word pno;
- byte b,startlno;
- string ts,s;
- uchar form[3];
- winptr hwinp;
-
- if (manstate == _located) initmanual("");
- if ((manstate == _opened) && (!manrecur) &&
- openwin(0,2,(byte)(scrhgt-2),(byte)(scrwid-2),2,whb,whb,8,"─┐│┘─└│┌",TopCnt,"") &&
- openwin(0,2,2,(byte)(scrwid-2),(byte)(scrhgt-5),whb,whb,0,"─┐│┤─├│┌",TopCnt,manual.name)) {
- form[0] = '4';
- form[1] = Pic_H;
- form[2] = '\0';
- manrecur = True;
- blank[2] = scrwid-2;
- mw = curwin;
- mw->disp = True;
- ixf.ipg = 1;
- ixf.ixp = 0;
- ixf.iyp = 0;
- ixf.pgstr[0] = '\0';
- ixf.ich = ' ';
- ovf.opg = 1;
- ovf.oyp = 1;
- ovf.pgstr[0] = '\0';
- cwinp = curwin->prvwin;
- writewxy(centre(ts,LSC_ManualMainMenu,cwinp->mwid),rhb,1,2,cwinp);
- loadpage(pageno,mw->mhgt); startlno = 1;
- cwinp->disp = True;
- dispwindow(cwinp);
- do {
- if (!kpressed())
- updatepage(pageno,(bool) (startlno > 1),(bool) (lines[startlno+mw->mhgt] != 0));
- dispwindow(mw);
- ukey = upperch(getkey());
- switch (ukey) {
- case HlpKey : hwinp = OnLineManualHelp();
- disphelpwin(hwinp);
- closewin(&hwinp);
- break;
- case F7 :
- case F8 :
- case F9 :
- ts[0] = '\0';
- if (ukey == F7) {
- xref(ts,crossref);
- strcopy(ts,ts,4,strlen(ts)-4);
- if (ts[0] != '\0')
- ukey = F9;
- else
- pno = pageno;
- }
- if (ukey == F8) pno = pickfromoview(pageno);
- if (ukey == F9) {
- writewxy(centre(s,LSC_IndexMenu,cwinp->mwid),rhb,1,2,cwinp);
- pno = pickfromindex(ts,pageno);
- }
- writewxy(centre(s,LSC_ManualMainMenu,cwinp->mwid),rhb,1,2,cwinp);
- if (pno != pageno) {
- pageno = pno;
- loadpage(pageno,mw->mhgt);
- startlno = 1;
- }
- else {
- mw->disp = False;
- lseek(manfile,lines[startlno],SEEK_SET);
- for (b = 1; b <=mw->mhgt; b++) {
- if (lines[b] != 0)
- dspln(b,pageno,mw->mhgt);
- else
- writeout(blank,wrattr,1,b);
- }
- mw->disp = True;
- }
- break;
- case UArr :
- if (startlno > 1) {
- startlno--;
- inscroll(_Up_,mw);
- lseek(manfile,lines[startlno],SEEK_SET);
- dspln(1,pageno,mw->mhgt);
- }
- break;
- case DArr :
- if (((MaxLines - startlno) >= mw->mhgt) && (lines[startlno+mw->mhgt] != 0)) {
- inscroll(_Down_,mw);
- lseek(manfile,lines[startlno+mw->mhgt],SEEK_SET);
- dspln(mw->mhgt,pageno,mw->mhgt);
- startlno++;
- }
- break;
- case LArr :
- case RArr : break;
- case PgUp :
- if (pageno > 1) {
- pageno--;
- loadpage(pageno,mw->mhgt);
- startlno = 1;
- }
- break;
- case PgDn :
- if (pageno < manh.totpages) {
- pageno++;
- loadpage(pageno,mw->mhgt);
- startlno = 1;
- }
- break;
- case Home :
- mw->disp = False;
- lseek(manfile,lines[1],SEEK_SET);
- for (b = 1; b <= mw->mhgt; b++) {
- if (lines[b] != 0) dspln(b,pageno,mw->mhgt);
- }
- startlno = 1;
- mw->disp = True;
- break;
- case EndKey :
- mw->disp = False;
- pno = mw->mhgt;
- while ((lines[pno+1] != 0) && (pno < MaxLines)) pno++;
- startlno = (byte) ((pno <= mw->mhgt) ? 1 : pno - mw->mhgt + 1);
- lseek(manfile,lines[startlno],SEEK_SET);
- for (b = 1; b <= mw->mhgt; b++) {
- if (lines[b] != 0) dspln(b,pageno,mw->mhgt);
- }
- mw->disp = True;
- break;
- case CtrlPgUp :
- pno = getchap(pageno);
- if (pno > 1) {
- pageno = (*mchaps)[pno-1];
- loadpage(pageno,mw->mhgt);
- startlno = 1;
- }
- break;
- case CtrlPgDn :
- pno = getchap(pageno);
- if (pno < manh.totchaps) {
- pageno = (*mchaps)[pno+1];
- loadpage(pageno,mw->mhgt);
- startlno = 1;
- }
- break;
- case CtrlHome :
- pageno = (*mchaps)[1];
- loadpage(pageno,mw->mhgt);
- startlno = 1;
- break;
- case CtrlEnd :
- pageno = (*mchaps)[manh.totchaps];
- loadpage(pageno,mw->mhgt);
- startlno = 1;
- break;
- case PAGE :
- dbgetstr(s,_Num,LSC_Page,"",form,"",nocheck,nohelp);
- pno = (word) ival(s);
- if ((pno >= 1) && (pno <= manh.totpages)) {
- pageno = pno;
- loadpage(pageno,mw->mhgt);
- startlno = 1;
- }
- break;
- case CHAPTER :
- dbgetstr(s,_Num,LSC_Chapter,"",form,"",nocheck,nohelp);
- pno = (word) ival(s);
- if ((pno >= 1) && (pno <= manh.totchaps)) {
- pageno = (*mchaps)[pno];
- loadpage(pageno,mw->mhgt);
- startlno = 1;
- }
- break;
- case Enter : break;
- case CtrlP : printman(pageno); break;
- case QitKey : break;
- }
- } while (ukey != QitKey);
- mw->disp = True;
- closewin(&mw);
- closewin(&cwinp);
- manrecur = False;
- }
- }
-
- /********************** UNIT INITIALIZATION/EXIT CODE *********************/
-
- void man_exit(void)
- {
- if ((manstate == _opened) || (manstate == _located)) {
- if (manstate == _opened) {
- outdev[0] = '\0';
- pageno = 1;
- manrecur = False;
- db_free(mpages);
- db_free(mchaps);
- }
- _close(manfile);
- manstate = _closed;
- }
- }
-
- void db_man_init(void)
- {
- if (!initialized) {
- initialized = True;
- db_curs_init();
- db_funcs_init();
- db_gvar_init();
- db_heap_init();
- db_key_init();
- db_win_init();
- db_mnu_init();
- db_util_init();
- outdev[0] = '\0';
- pageno = 1;
- manrecur = False;
- morehelp = dispmanual;
- atexit(man_exit);
- }
- }
-
- /***************************** END OF DB_MAN.C ****************************/
-